﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Fintech.Utils;

namespace ZOVNP.WinView
{
    class CustomerOrdersTreePopulationStrategies : IOrdersTreePopulationStrategy
    {
        public readonly Guid _id;
        public readonly string _text;

        public CustomerOrdersTreePopulationStrategies()
        {
            _text = "По покупателям";
            _id = new Guid("9A1CD9C4-A441-4A2E-AD86-C99947BE6359");
        }

        public Guid ID { get { return _id; } }
        public string Text { get { return _text; } }

        public void PopulateTree(TreeView treeView, IEnumerable<OrderNode> nodes)
        {
            var customerGroups = nodes.GroupBy(n => n.Order.CustomerID);
            customerGroups.ForEach(mg =>
            {
                var node = new TreeNode(mg.First().Order.Customer.ToString());
                mg.ForEach(n => node.Nodes.Add(n));
                treeView.Nodes.Add(node);
            });
        }

        public override string ToString()
        {
            return _text;
        }
    }
}
